import {defineStore} from "pinia"

/**
 * 定义与用户相关的 Store
 * 'userStore' 为定义的 Store 的 id
 *
 * @type {StoreDefinition<string, {}, {}, {}>}
 */
const useAccountStore = defineStore(
    'accountStore',
    {
        state: () => ({
            // 账号
            account: '',
            // 账户信息
            manager: null
        }),
        actions: {
            saveAccount(account) {
                this.account = account
            },
            // 保存用户登录后的信息
            saveManager(manager) {
                this.manager = manager
            },
            clear() {
                this.account = null
                this.manager = null
            }
        },
        getters: {

        },
        persist: {
            enabled: true,
            strategies: [
                {
                    key: 'accountStore',
                    storage: window.localStorage,
                    paths: ['account']
                }
            ]
        }
    }

)

/**
 * 导出 Store
 */
export default useAccountStore